package com.wy._05Random.Enum;

/**
 * unicode 片段对象
 */
public class UnicodeFragment {
    //这一个片段也有一个名字
    private String fragmentName;
    private int count;
    private int startCoding;
    private int endCoding;

    public UnicodeFragment(String fragmentName, int startCoding, int endCoding) {
        this.fragmentName = fragmentName;
        this.startCoding = startCoding;
        this.endCoding = endCoding;
        this.count = calculateCount(); // 在构造函数中计算count
    }

    public String getFragmentName() {
        return fragmentName;
    }

    public void setFragmentName(String fragmentName) {
        this.fragmentName = fragmentName;
    }

    public int getCount() {
        return count;
    }

    // 通常情况下，你可能不需要设置count，因为它是由startCoding和endCoding计算得出的
    // 如果确实需要，可以保留这个方法
    public void setCount(int count) {
        this.count = count;
    }

    public int getStartCoding() {
        return startCoding;
    }

    public void setStartCoding(int startCoding) {
        this.startCoding = startCoding;
        this.count = calculateCount(); // 更新count值
    }

    public int getEndCoding() {
        return endCoding;
    }

    public void setEndCoding(int endCoding) {
        this.endCoding = endCoding;
        this.count = calculateCount(); // 更新count值
    }

    private int calculateCount() {
        return endCoding - startCoding + 1;
    }

    @Override
    public String toString() {
        return "UnicodeFragment{" +
                "fragmentName='" + fragmentName + '\'' +
                ", count=" + count +
                ", startCoding=" + startCoding +
                ", endCoding=" + endCoding +
                '}';
    }
}
